<?
require_once(dirname(__FILE__).'/class/Disk.class.php');
#require_once(dirname(__FILE__).'/class/Partition.class.php');
require_once(dirname(__FILE__).'/class/FS.class.php');
require_once(dirname(__FILE__).'/class/AV.class.php');
require_once(dirname(__FILE__).'/class/KasperskyAV.class.php');
require_once(dirname(__FILE__).'/class/ClamAV.class.php');
require_once('include/progressbar.php');


$devpath=$_GET['dev'];

if ($fs=new FS($devpath)){
    if ($fs->isMounted()){
            $mountpoint=$fs->getMountpoint();
            $label=$fs->label;
    } else {
        // Fix: entra aquí aunque no sea un FS o un disco/particion
        //echo ("Partition is not mounted\n");
        $label='is not a partition';
        $mountpoint=$devpath;
        //exit(1);
    }
} else {
    $label='is not a partition';
    $mountpoint=$devpath;
}

#$av=new KasperskyAV();
$av=new ClamAV();
$av->startAnalyzer($mountpoint);
?>

<html>
<head>
<title>garbirus!</title>
<style type="text/css">
 <!--
  <?=pbCssStyle();?>
   -->
   </style>
</head>
<body>
<h2>Scan</h2>
 <ul>
    <li>Dev: <?=$devpath?></li>
    <li>Label: <?=$label?> </li>
    <li>Mountpoint: <?=$mountpoint?></li>
 </ul>
<br \>
<h2>Analyzing...</h2>
 <ul>
<?
if (ob_get_level() == 0) {
    ob_start();
}

$i=0;
$d=0;
echo str_pad(' ',4096)."<br />\n";

while ($av->isRunning()){
    if ($i<22){
        $i++;
        $d=$d+11;
        echo '<div class="percents">' . $i*4 . '%&nbsp;complete</div>';
        echo '<div class="blocks" style="left: '.$d.'px">&nbsp;</div>';
        flush();
        ob_flush();
    }
    sleep (1);
}
ob_end_flush();
?>
<div class="percents" style="z-index:12">Done.</div>
<br />
<br />
<h2>Summary</h2>
 <ul>
<?
foreach($av->printStats() as $line){
    if ($line != "\n"){
        if (substr_count($line, 'Infected')>0){
?>
            <li><b><?=$line?></b></li>
<?
        } else {
?>
            <li><?=$line?></li>
<?
        }
    }
}

// Umounting device
if ($fs->isMounted()){
    $fs->umount();
}

?>
 </ul>

</body>
</html>
